// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import Vuex from 'vuex'
import axios from 'axios'
import global_ from '@/api/global'
import const_ from '@/api/const'
import chart_ from '@/api/chart'
import db from '@/utils/localstorage'
import './assets/css/index.css'
import Es6Promise from 'es6-promise'
// 引入nprogress
import NProgress from 'nprogress' // 进度条
import 'nprogress/nprogress.css' // 这个样式必须引入
import * as echarts from 'echarts'

Es6Promise.polyfill()

// 简单配置
NProgress.inc(0.2)
NProgress.configure({easing: 'ease', speed: 500, showSpinner: false})
router.afterEach(() => {
    NProgress.done()
})

Vue.prototype.$echarts = echarts

Vue.use(ElementUI);
Vue.use(Vuex);
Vue.prototype.$axios = axios;
Vue.prototype.GLOBAL = global_;
Vue.prototype.CONST = const_;
Vue.prototype.CHART = chart_;
Vue.prototype.db = db;

import ElTableFixedHeader from 'el-table-fixed-header'
Vue.use(ElTableFixedHeader)

axios.defaults.headers.post['Content-Type'] = 'application/json';

Vue.config.productionTip = false;

const store = new Vuex.Store({
    // 全局状态定义
    state: {
        count: 10,
        token: '',
    },
    // 相当于计算属性
    getters: {
        format: state => {
            return state.count + "RMB"
        }
    },
    // 通过这里更改全局状态，同步执行
    mutations: {
        increment(state) {
            state.count++;
        },
        setToken(state, value) {
            state.token = value;
        }
    },
    // 通过这里更改全局状态，这里可以设置异步执行
    actions: {
        increment(context) {
            context.commit('increment');
        }
    }
})

/* eslint-disable no-new */
new Vue({
    el: '#app',
    store,
    router,
    components: {App},
    template: '<App/>'
})


